package com.hgy.plugin.security.realm;

import org.apache.shiro.realm.jdbc.JdbcRealm;

import com.hgy.framework.helper.DatabaseHelper;
import com.hgy.plugin.security.SecurityConfig;
import com.hgy.plugin.security.password.Md5CredentialsMatcher;

/**
 * 基于 Smart 的 JDBC Realm (需要提供相关的 smart.plugin.security.jdbc.* 配置项)
 * 
 * @author alone
 *
 */
public class SmartJdbcRealm extends JdbcRealm{
	
	
	public SmartJdbcRealm() {
		super.setDataSource(DatabaseHelper.getDataSource());
		super.setAuthenticationQuery(SecurityConfig.getJdbcAuthcQuery());
		super.setUserRolesQuery(SecurityConfig.getJdbcRolesQuery());
		super.setPermissionsQuery(SecurityConfig.getJdbcPermissionQuery());
		// 开启连接 permission 表查询
		super.setPermissionsLookupEnabled(true);
		// 自定义 MD5密码匹配
		super.setCredentialsMatcher(new Md5CredentialsMatcher());
		
	}
	
}
